<!DOCTYPE html>
<html>

{include file='public/header'}
<style>
    .layui-table-view{
        margin: 0;
    }
</style>
<body>
    <table id="see" lay-filter="see"></table>
    <script type="text/html" id="toolbar">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm" id="batchUploadThird" lay-event="batchUploadThird">批量上传</button>
            <button class="layui-btn layui-btn-sm" id="batchBinding" lay-event="batchBinding">批量绑定</button>
            <button class="layui-btn layui-btn-sm" id="batchPageBinding" lay-event="batchPageBinding">页面批量绑定</button>
        </div>
    </script>
    <script type="text/html" id="tbBar">
        <a class="layui-btn layui-btn-xs layui-btn-xs" lay-event="upload">上传</a>
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="binding">绑定</a>
        <a class="layui-btn layui-btn-xs" lay-event="pageBinding">页面绑定</a>
    </script>

    <script>
        let audit_status_txt = {
            'none': '待送审',
            'auditing': '审核中',
            'fail': '不可播放',
            'success': '可播放'
        };
        let id = GetQueryString('id')
        let video_name = GetQueryString('video_name')
        let params = {
            elem: '#see'
            , toolbar: '#toolbar'
            , url: '/admin/thirdVideo/view' //数据接口
            , id: 'see'
            , page:true
            , where:{id}
            , height: 600
            , cols: [[ //表头
                { type: 'checkbox' }
                , { field: 'id', title: 'ID', width: 100, sort: true,align:'center' }
                , { field: 'name', title: '剧集名称', align:'center'}
                , { field: 'platform', title: '平台', align:'center',
                    templet: function (d) {
                        return d.platform === 2 ? '抖音' : '';
                    }
                }
                , { field: 'episode_id', title: 'episode_id', align:'center'}
                , { field: 'upload_status', title: '上传状态',align:'center',
                    templet: function (d) {
                        return d.upload_status >= 1 ? '已上传' : '未上传';
                    } 
                }
                , { field: 'binding_status', title: '绑定状态',align:'center',
                    templet: function (d) {
                        return d.binding_status >= 1 ? '已绑定' : '未绑定'
                    } 
                }
                , { field: 'page_binding_status', title: '页面绑定状态',align:'center',
                    templet: function (d) {
                        return d.page_binding_status >= 1 ? '已绑定' : '未绑定'
                    }
                }
                , { field: 'audit_status', title: '审核状态',align:'center',
                    templet: function (d) {
                        return audit_status_txt[d.audit_status] ?? ''
                    }
                }
                , { toolbar: '#tbBar', title: '操作',align:'center',width:270}
            ]]
        }

        tableList(params)

        layui.use('table', function () {
            var table = layui.table;
            table.on('toolbar(see)', function (obj) {
                var event = obj.event;
                var checkStatus = table.checkStatus('see')
                if(checkStatus.data.length === 0) {
                    layer.msg('请选择后再操作',{icon:5,time:1000});
                    return;
                }
                let id_string = []
                checkStatus.data.forEach(item=>{
                    id_string.push(item.id)
                })
                if (event === 'batchUploadThird') {
                    AnyAjax('确定上传么？','/admin/mediaAssets/uploadVideos', { id:id,ep_ids:id_string }, 'see')
                } else if(event === 'batchBinding'){
                    AnyAjax('确定绑定么？','/admin/mediaAssets/syncVideos',{ id:id,ep_ids:id_string },'see')
                } else if (event === 'batchPageBinding') {
                    AnyAjax('确定绑定页面么？','/admin/mediaAssets/pageBind',{ id:id,ep_ids: id_string },'see')
                }
            });

            table.on('tool(see)', function (obj) {
                var event = obj.event;
                if (event === 'upload') {
                    AnyAjax('确定上传么？','/admin/mediaAssets/uploadVideos', { id:id,ep_ids:[obj.data.id] }, 'see')
                } else if (event === 'binding') {
                    AnyAjax('确定绑定么？','/admin/mediaAssets/syncVideos',{ id:id,ep_ids: [obj.data.id] },'see')
                } else if (event === 'pageBinding') {
                    AnyAjax('确定绑定页面么？','/admin/mediaAssets/pageBind',{ id:id,ep_ids: [obj.data.id] },'see')
                }
            });
        });
    </script>
</body>

</html>